//
//  LGAddMedicinLineView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/16.
//

#import "LGAddMedicinLineView.h"

@interface LGAddMedicinLineView()
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UILabel *unitLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGAddMedicinLineView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
}

-(void)setContent:(NSString *)content{
    _content = content;
    NSString *colorName = (content.length>0)?@"#666666":@"#999999";
    self.contentLabel.font = (content.length>0)?LGFont(16):LGFont(15);
    self.contentLabel.textColor = [UIColor colorWithString:colorName];
    self.contentLabel.text = (content.length>0)?content:@"请选择";
    CGFloat width = [content textWidthWithFont:LGFont(16) maxHeight:MAXFLOAT];
    NSTextAlignment alignment = (width>Screen_W-viewPix(138))?NSTextAlignmentLeft:NSTextAlignmentRight;
    self.contentLabel.textAlignment = alignment;
}

-(void)setShowTip:(BOOL)showTip{
    _showTip = showTip;
    self.tipView.hidden = !showTip;
}

-(void)createSubView{
    self.backgroundColor = [UIColor whiteColor];
    [self setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.1 radius:15];
    [self addSubview:self.titleLabel];
    [self addSubview:self.contentLabel];
    [self addSubview:self.unitLabel];
    [self addSubview:self.tipView];
    [self addSubview:self.actionBtn];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(viewPix(16));
        make.centerY.equalTo(self);
        make.width.equalTo(@(viewPix(70)));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(viewPix(10));
        make.right.equalTo(self.unitLabel.mas_left);
        make.centerY.equalTo(self);
    }];
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.tipView.mas_left);
        make.centerY.equalTo(self.contentLabel).offset(viewPix(2));
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-viewPix(12));
        make.width.height.equalTo(@(viewPix(12)));
        make.centerY.equalTo(self);
    }];
    [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self);
    }];
}


-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"请选择" colorString:@"#999999" textFont:LGFont(15) textAlignment:NSTextAlignmentRight lines:2];
    }
    return _contentLabel;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _unitLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

-(UIButton *)actionBtn{
    if(!_actionBtn){
        _actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _actionBtn;
}

@end
